<template>
  <div class="app-container">
    <div>
      <el-form :inline="true" class="search-form" size="small">
        <el-row style="display: flex; flex-wrap: wrap">
          <div style="flex: 1">
            <el-form-item label="类目：" class="search-form-item">
              <el-cascader clearable v-model="value" :options="typeData" :props="{
                    expandTrigger: 'hover',
                    checkStrictly: true,
                    value: 'id',
                    label: 'category_name',
                  }" @change="handleChange" placeholder="请选择类目"></el-cascader>
            </el-form-item>
            <el-form-item label="供应商：" class="search-form-item">
              <el-select style="width: 100%" clearable v-model="query.supplier_name" filterable
                placeholder="请输入供货商名称搜索">
                <el-option v-for="item in options" :key="item.id" :label="item.supplier_name"
                  :value="item.supplier_name">
                </el-option>
              </el-select>
            </el-form-item>

          </div>
          <div style="margin: 5px 0; text-align: right">
            <el-button size="small" type="primary" icon="el-icon-search" @click="search">查询</el-button>
            <el-button size="small" type="primary" icon="el-icon-refresh" @click="resetting">重置</el-button>
            <el-button v-if="!searchDisplay" size="small" icon="el-icon-caret-bottom"
              @click="searchDisplay = true">展开</el-button>
            <el-button v-else size="small" icon="el-icon-caret-top" @click="searchDisplay = false">收起</el-button>
          </div>
        </el-row>
        <el-row v-if="searchDisplay" style="display: flex">
          <el-form-item label="名称：" class="search-form-item">
            <el-input clearable v-model="query.goods_name" placeholder="请输入产品名称" />
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <!-- tab -->
    <el-divider></el-divider>
    <div class="table-module">
      <div style="margin-bottom: 10px;">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="16">
            <div class="left-panel">
              <el-button type="text" icon=""></el-button>
            </div>
          </el-col>
          <el-col :xs="24" :sm="8">
            <div class="right-panel el-button-group">
              <el-button class="" icon="el-icon-refresh" size="mini" @click="resetting"></el-button>
              <el-dropdown trigger="click" :hide-on-click="false">
                <span class="el-dropdown-link">
                  <el-button class="" icon="el-icon-s-operation" size="mini"></el-button>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="fruit in allTableThead" :key="fruit">
                    <el-checkbox v-model="checkboxTableThead"
                      :label="fruit">{{ tableTheadOptions[fruit].label }}</el-checkbox>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </el-col>
        </el-row>
      </div>
      <!-- 订单列表 -->
      <el-row :gutter="20">
        <el-col class="">
          <el-table ref="tablerefs" v-loading="loading" highlight-current-row :data="tableData" :header-cell-style="{
                'background-color': '#f3f8fe',
                color: '#606266',
                height: '50px',
              }" style="width: 100%" height="500">
            <el-table-column v-for="fruit in tableThead" :key="fruit" :label="tableTheadOptions[fruit].label" :width="
                  tableTheadOptions[fruit].width
                    ? tableTheadOptions[fruit].width + 'px'
                    : 'auto'
                " align="center">
              <template slot-scope="scope">
                <div v-if="fruit == 'supplier_name'">
                  <el-tooltip placement="top-start" :content="scope.row.supplier_name + ''">
                    <div class="one_line_hidden" style="color: #0076f6;">
                      {{ scope.row.supplier_name}}
                    </div>
                  </el-tooltip>
                </div>
                <div v-else-if="fruit == 'main_image'">
                  <div style="
                        width: 30px;
                        height: 30px;
                        border-radius: 5px;
                        overflow: hidden;
                        margin: 0 auto;
                      ">
                    <el-image v-if="scope.row.main_image" :src="scope.row.main_image"
                      :preview-src-list="[scope.row.main_image]" />
                  </div>
                </div>
                <div v-else-if="fruit == 'status'">
                  <span style="margin: 0 3px;color: #f86d60;" v-if="scope.row.status == 0">禁用</span>
                  <span v-else style="margin: 0 3px;color:#13ce66;">启用</span>
                </div>
                <div v-else>
                  <el-tooltip placement="top-start" :content="scope.row[fruit] + ''">
                    <div class="one_line_hidden">
                      {{ scope.row[fruit] ? scope.row[fruit] : "-" }}
                    </div>
                  </el-tooltip>
                </div>
              </template>
            </el-table-column>
            <!-- <el-table-column fixed="right" width="120" prop="address" label="操作" align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="goods_detail(scope.row)">
                  详情
                </el-button>
              </template>
            </el-table-column> -->
          </el-table></el-col>
      </el-row>
      <el-row>
        <el-col style="text-align: right">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="query.page" :page-sizes="[10, 20, 30, 40]" :page-size="query.count"
            layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
  import {
    getList,
    getDetail
  } from "@/api/merchant/index";

  import {
    goodslist,
    getCateLis,
    supplierLists,
    getSupplierGoodsInfo,
  } from "@/api/supplier/index";
  const tableTheadOption = {
    id: {
      label: "ID",
      field: "id",
      width: 80,
    },
    supplier_name: {
      label: "供货商",
      field: "supplier_name",
      width: 160,
    },
    mgsl_name: {
      label: "商品名称",
      field: "mgsl_name",
    },
    sub_title: {
      label: "副标题",
      field: "sub_title",
      width: 140,
    },
    sales_total_price: {
      label: "销售额(余额)",
      field: "sales_total_price",
      width: 120,
    },
    sales_total_points: {
      label: "销售额(积分)",
      field: "sales_total_points",
      width: 120,
    },
    sales_total_coupon: {
      label: "销售额(提货券)",
      field: "sales_total_coupon",
      width: 120,
    },
    inventory_total: {
      label: "商品库存",
      field: "inventory_total",
      width: 120,
    },
    sales_total_num: {
      label: "销售数量",
      field: "sales_total_num",
      width: 100,
    },
    main_image: {
      label: "产品主图",
      field: "main_image",
    },
  };
  const allTableThead = [
    "id",
    "supplier_name",
    "mgsl_name",
    "inventory_total",
    "sales_total_num",
    "sales_total_price",
    "sales_total_points",
    "sales_total_coupon",
    "main_image",

  ];
  const defaultTableThead = [
    "id",
    "supplier_name",
    "main_image",
    "mgsl_name",
    "inventory_total",
    "sales_total_num",
    "sales_total_price",

  ];
  export default {
    name: "merchantProducts",
    components: {

    },
    data() {
      return {
        searchDisplay: false,
        SupplierList: [],

        Infodetail: "",
        kucunData: [],
        editdialogVisible: false,
        id: "",
        svalue: "",
        options: [],
        values: "点击关闭",
        dialogVisible: false,
        loading: true,
        direction: "rtl", //抽屉的出来形式
        currentPage4: 1, //页码
        value: "",
        total: 0,
        query: {
          page: 1,
          count: 10,
          mer_id:"",
          goods_name: "",
          category_ids: "",
          supplier_name: "",
        },
        radio1: "1",
        tableData: [], //列表
        typeData: [], //类目list
        multipleSelection: [], //勾选的订单
        goodsdetail: {},
        tableKey: 1, // table key
        tableTheadOptions: tableTheadOption,
        allTableThead: allTableThead,
        tableThead: defaultTableThead, // 默认表头
        checkboxTableThead: defaultTableThead, // 默认表头值
        skulist: [],
        sku_imgs: {},
        detailLoading: false,
      };
    },
    watch: {
      checkboxTableThead(valArr) {
        this.tableThead = this.allTableThead.filter(
          (i) => valArr.indexOf(i) >= 0
        );
        this.tableKey = this.tableKey + 1; // 为了保证table 每次都会重渲
        this.$nextTick(() => {
          this.$refs.tablerefs.doLayout();
        });
      },
    },
    mounted() {
      // this.getlist(); //产品列表
      this.getcartlist(); //类目列表
      this.SupplierLists(); //供应商列表

    },
    methods: {
      //库存明细
      inventory_details(row) {
        // this.$refs.refInventory.open(row)
      },
      //详情
      goods_detail(row) {
        // this.$refs.refDetail.open(row)
      },
      //重置
      resetting() {
        this.value = ''
        this.query.goods_name = "";
        this.query.category_ids = "";
        this.query.supplier_name = "";
        this.getlist(this.query.mer_id);
      },
      //切换搜索分类
      handleChange(value) {

        this.query.category_ids = value.join(',');
      },
      //供应商列表
      SupplierLists() {
        supplierLists().then((res) => {
          this.options = res.data;
        });
      },
      //类目列表
      getcartlist() {
        getCateLis().then((res) => {
          this.typeData = res.data;
        });
      },
      //产品列表
      getlist(id) {
        this.loading = true;
        this.query.mer_id = id
        getList(this.query).then((res) => {
          this.loading = false;
          this.currentPage4 = res.data.currentPage;
          this.total = res.data.total;
          this.tableData = res.data.list;
        });
      },
      // 选中的每条列表
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      //查看订单详情
      detailorder(row) {
        this.id = row.id;
        this.goodsdetail = row;
        this.drawer = true;
        this.detailLoading = true;
        getSupplierGoodsInfo({
          id: row.id
        }).then((res) => {
          this.goodsdetail = res.data;
          this.Infodetail = res.data.goods_detail.detail.replace(
            /<img/g,
            '<img mode="widthFix" style="max-width:100%;"'
          );
          this.Infodetail = this.Infodetail.replace(
            /width: 750px/g,
            "width: 100%"
          );
          this.detailLoading = false;
        });
      },
      //页码
      handleSizeChange(val) {
        this.query.count = val
        this.getlist(this.query.mer_id);
      },
      handleCurrentChange(val) {
        console.log(val,"66")
        this.query.page = val
        this.getlist(this.query.mer_id);
      },
      //点击搜索
      search() {
        this.getlist(this.query.mer_id);
      },
    },
  };
</script>

<style lang="scss">
  .title {
    color: rgba(0, 0, 0, 0.85);
    font-weight: 500;
    font-size: 16px;
    line-height: 16px;
  }

  .sn {
    color: #606266;
    font-size: 13px;
  }

  .order_center {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 50px 0 0;
    font-size: 13px;
    color: #666;
  }

  .fleximg {
    font-size: 12px;
    display: flex;
    align-items: center;
    color: #606266;
  }

  // #addgoods .single-image-uploader-icon{
  //   width: 90px;
  //   height: 90px;
  // }
  // #addgoods .single-image-uploader{
  //   width: 90px;
  //   height: 90px;
  // }
  // #addgoods .el-upload {
  //   width: 90px;
  //   height: 90px;
  // }
  // #addgoods .el-upload--text{
  //   width: 90px;
  //   height: 90px;
  // }
  // #addgoods .single-image-uploader-icon{
  //   line-height: 90px;
  // }
  // #addgoods .single-image{
  //   width: 90px;
  //   height: 90px;
  // }
  #addgoods .el-upload--picture-card {
    width: 90px !important;
    height: 90px !important;
    line-height: 90px;
  }

  #addgoods .el-upload-list--picture-card .el-upload-list__item-actions {
    width: 90px !important;
    height: 90px !important;
  }

  #addgoods .el-upload-list--picture-card .el-upload-list__item-thumbnail {
    width: 90px !important;
    height: 90px !important;
  }

  #addgoods .el-upload-list--picture-card .el-upload-list__item {
    width: 90px !important;
    height: 90px !important;
  }
</style>
<style lang="scss" scoped>
  .phone {
    position: relative;
    margin-left: 50%;
    width: 380px;
    height: 800px;
    border: 5px solid #949494;
    border-radius: 40px;
    transform: scale(0.8) translateY(-50px);
  }

  .phone:before {
    content: "";
    position: absolute;
    width: 369px;
    height: 789px;
    // box-shadow: 0px 0px 24px #000;
    background-color: #000;
    border-radius: 33px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .phone:after {
    content: "";
    position: absolute;
    width: 364px;
    height: 786px;
    background: #fff;
    border-radius: 28px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .html {
    position: absolute;
    width: 364px - 5px - 5px;
    height: 786px - 5px - 5px;
    background: #fff;
    border-radius: 30px;
    overflow: hidden;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 5px;
    z-index: 1;
  }

  .receiver {
    position: absolute;
    top: 5px;
    left: 50%;
    margin-left: -50px;
    background: #000000;
    border: #484848 1px solid;
    width: 100px;
    height: 8px;
    z-index: 9;
    border-radius: 20px;
  }

  .receiver ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    margin: 1px;
    justify-content: space-around;
  }

  .receiver ul li {
    background: #303030;
    width: 1px;
    height: 1.5px;
    float: left;
    transform: skewX(-38deg);
  }

  .receiver div {
    width: 100px;
    height: 8px;
  }

  .receiver div:after {
    content: "";
    display: block;
    width: 95%;
    height: 83%;
    top: 1px;
    left: 3px;
    position: absolute;
    background-repeat: no-repeat;
    background-image: repeating-linear-gradient(to right,
        #434242,
        #000000 1px,
        rgba(255, 255, 255, 0) 1px,
        rgba(255, 255, 255, 0) 3px),
      repeating-linear-gradient(to right,
        #434242,
        #19191d 1px,
        rgba(255, 255, 255, 0) 1px,
        rgba(255, 255, 255, 0) 3px);
    background-size: 100% 50%;
    background-position: 0 0, 2px 4px;
    transform: skew(-25deg);
  }

  .labelView {
    width: 150px;
  }
</style>
<style lang="scss">
  .el-divider--horizontal {
    margin: 10px 0 !important;
  }

  .search-form-item {
    padding-bottom: 10px;
    padding-right: 20px;

    .el-form-item__label {
      font-size: 12px;
      font-weight: 500;
      // width:96px;
    }

    .el-input {
      width: 180px;
    }
  }

  .tabsView {
    margin-top: 10px;
  }

  .el-tabs__nav-wrap::after {
    background-color: #dfe4ed00;
  }

  .el-descriptions__header {
    margin-bottom: 0;
  }

  .el-descriptions__title {
    flex: 1;
  }
</style>
